package com.mall.goods.controller;

import com.mall.commons.utils.CommonResult;
import com.mall.goods.service.PmsProductCategoryService;
import com.mall.model.dto.PmsProductCategoryDto;
import com.mall.model.vo.CommonPage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/productCategory")
public class PmsProductCategoryController {

    @Autowired
    private PmsProductCategoryService pmsProductCategoryService;

    /**
     * 查询所有一级分类及子分类
     *
     * @return
     */
    @GetMapping("/list/withChildren")
    public CommonResult listWithChildren() {
        List list = pmsProductCategoryService.listWithChildren();
        return CommonResult.success(list);
    }

    /**
     * 分页查询商品分类
     *
     * @return
     */
    @GetMapping("list/{parentId}")
    public CommonResult list(@PathVariable("parentId") Integer parentId,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "5") Integer pageSize) {
        log.info("parentId:{},pageNum:{},pageSize:{}", parentId, pageNum, pageSize);
        CommonPage commonPage = pmsProductCategoryService.listPage(parentId, pageNum, pageSize);
        return CommonResult.success(commonPage);
    }

    /**
     * 添加商品分类
     *
     * @return
     */
    @PostMapping("/create")
    public CommonResult create(@RequestBody PmsProductCategoryDto pmsProductCategoryDto) {
        log.info("pmsProductCategoryDto:{}", pmsProductCategoryDto);
        return null;
    }

}
